package com.example.textviewactivity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class RadioButtonActivity extends AppCompatActivity  implements RadioGroup.OnCheckedChangeListener{
    RadioGroup rb,rbclass;
    RadioButton boy,girl,class1,class2,class3;
    Button btn;
    String text="";
    String cls="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_radio_button);
        init();
    }

    public void init(){
        rb=findViewById(R.id.rb);
        boy=findViewById(R.id.boy);
        girl=findViewById(R.id.girl);
        btn=findViewById(R.id.btn);
        class1=findViewById(R.id.class1);
        class2=findViewById(R.id.class2);
        class3=findViewById(R.id.class3);
        rbclass=findViewById(R.id.rbclass);
        rbclass.setOnCheckedChangeListener(this);
        rb.setOnCheckedChangeListener(this);

        rbclass.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i==class1.getId()){
                    cls=class1.getText().toString();
                }else if (i==class2.getId()){
                    cls=class2.getText().toString();
                }else if(i==class3.getId()){
                    cls=class3.getText().toString();
                }
            }
        });
    }



    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        int buttonId = radioGroup.getCheckedRadioButtonId();
        RadioButton viewById = findViewById(buttonId);
        text=viewById.getText().toString();
    }

    public void load(View view){
        Toast.makeText(this, text+"-----------"+cls, Toast.LENGTH_SHORT).show();
    }
}
